package com.xms.file.service;

import com.xms.security.identity.ICurrentUser;
import com.xms.utils.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ClassUtils;

import java.io.File;

/**
 * <p>
 * AttachmentSettings
 * </p>
 *
 * @author migo
 * @since 2021/9/27
 */
@Service
public class AttachmentSettings implements IAttachmentSettings {
    @Value("${xms.upload.folder}")
    private String uploadFolder;
    private ICurrentUser _currentUser;

    public AttachmentSettings(ICurrentUser currentUser){
        _currentUser = currentUser;
    }

    @Override
    public String getRootPath() {
        return ClassUtils.getDefaultClassLoader().getResource("").getPath()
                + uploadFolder + "/";
    }

    @Override
    public String getUploadFolder(){
        return uploadFolder + "/" + _currentUser.getUser().OrganizationId.toString();
    }

    @Override
    public String getAbsoluteUploadFolder() {
        return this.getRootPath() + _currentUser.getUser().OrganizationId.toString();
    }
}
